package net.studou.convert;

import java.util.Set;

import net.studou.bean.tools.IConvert;
import net.studou.po.Task;

public class TaskCountConvert implements IConvert {

	public static final int TASK_STATE_ONE = 1;
	public static final int TASK_STATE_TWO = 2;
	public static final int TASK_STATE_THREE = 3;
	public static final int TASK_STATE_FOUR = 4;
	public static final int TASK_STATE_FIVE = 5;
	public static final int TASK_STATE_SIX = 6;
	public static final int TASK_STATE_SEVEN = 7;

	private int taskState;

	public TaskCountConvert(Integer taskState) {
		this.taskState = taskState;
	}

	@SuppressWarnings("unchecked")
	public Object convert(Object value) throws Exception {
		int count1 = 0;
		int count2 = 0;
		int count3 = 0;
		int count4 = 0;
		int count5 = 0;
		int count6 = 0;
		int count7 = 0;
		Set<Task> tasks = (Set<Task>) value;
		for (Task task : tasks) {
			int state = task.getStatus();
			switch (state) {
			case 10:
				count1++;
				break;
			case 20:
				count2++;
				break;
			case 30:
				count3++;
				break;
			case 40:
				count4++;
				break;
			case 50:
				count5++;
				break;
			case 60:
				count6++;
				break;
			case 70:
				count7++;
				break;
			default:
				break;
			}
		}
		switch (taskState) {
		case TaskCountConvert.TASK_STATE_ONE:
			return count1 + "";
		case TaskCountConvert.TASK_STATE_TWO:
			return count2 + "";
		case TaskCountConvert.TASK_STATE_THREE:
			return count3 + "";
		case TaskCountConvert.TASK_STATE_FOUR:
			return count4 + "";
		case TaskCountConvert.TASK_STATE_FIVE:
			return count5 + "";
		case TaskCountConvert.TASK_STATE_SIX:
			return count6 + "";
		case TaskCountConvert.TASK_STATE_SEVEN:
			return count7 + "";
		default:
			return 0;
		}

	}
}
